package FirstAssignment;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class RedPanel extends MouseAdapter {

    private TurnRed turnRed;

    //传出颜色
    protected Color currentColor;

    public RedPanel(TurnRed turnRed){

        this.turnRed=turnRed;

        currentColor=turnRed.getContentPane().getBackground();

    }

    //鼠标点击
    @Override
    public void mouseClicked(MouseEvent e) {

        JPanel jPanel = (JPanel) e.getSource();

        turnRed.getContentPane().setBackground(jPanel.getBackground());

        this.currentColor=jPanel.getBackground();

    }

    //鼠标进入
    @Override
    public void mouseEntered(MouseEvent e) {

        JPanel jPanel = (JPanel) e.getSource();

        turnRed.getContentPane().setBackground(jPanel.getBackground());
    }

    //鼠标出去

    @Override
    public void mouseExited(MouseEvent e) {

        turnRed.getContentPane().setBackground(this.currentColor);
    }

    public Color getCurrentColor() {

        return currentColor;
    }
}
